package scala.pattern

/**
 * 匹配类型
 */
object MatchValTest1 {
  def main(args: Array[String]): Unit = {



//    def describe(x: Any) = x match {
//      case 5 => "Int five"
//      case "hello" => "String hello"
//      case true => "Boolean true"
//      case '+' => "Char +"
//    }

    def describeType(x:Any) = x match {
      case i : Int => "int"
      case u : String => "string"
      case m : List[_] => "list"
      case c : Array[Int] => "Array[Int]"
      case s : Array[String] => "Array[String]"
    }

    //      泛型擦除
    println(describeType(List(1, 2, 3, 4)))

    //  数组例外，可保留泛型
    println(describeType(Array(1,2,3,4,5,56)))

    println(describeType(Array("abc")))
  }
}
